﻿package com.wandian.view.mediator.shop
{
	import com.wandian.controller.AccountCommand;
	import com.wandian.controller.CLZNoticeName;
	import com.wandian.controller.ShopCommand;
	import com.wandian.data.GameData;
	import com.wandian.model.InRoomPlayerDataProxy;
	import com.wandian.model.SwfDataProxy;
	import com.wandian.model.vo.PlayerVo;
	import com.wandian.model.vo.RoomVo;
	import com.wandian.util.CLZButton;
	import com.wandian.util.CLZTabBar;
	import com.wandian.util.GlowFilterManage;
	import com.wandian.util.GolbalTimer;
	import com.wandian.view.components.ui.AddBtn;
	import com.wandian.view.components.ui.MaskTipPanel;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	
	import org.puremvc.as3.interfaces.*;
	import org.puremvc.as3.patterns.mediator.*;

    public class ShopMediator extends Mediator
    {
        private var _global:GameData;
        private var _tabBar:CLZTabBar;
        private var _nType:int;
        private var _onPlayerVo:PlayerVo;
        public static const NAME:String = "ShopMediator";

        public function ShopMediator(param1:MovieClip, param2:int, param3:PlayerVo)
        {
            this._global = GameData.getInstance();
            this._nType = param2;
            this._onPlayerVo = param3;
            super(NAME, param1);
            return;
        }

        override public function onRegister() : void
        {
            facade.registerCommand(CLZNoticeName.SHOP_HOT_PROP_LIST_REQ, ShopCommand);
            facade.registerCommand(CLZNoticeName.SHOP_INTERACTIVE_PROP_LIST_REQ, ShopCommand);
            facade.registerCommand(CLZNoticeName.SHOP_GIFT_LIST_REQ, ShopCommand);
            facade.registerCommand(CLZNoticeName.SHOP_VIP_LIST_REQ, ShopCommand);
            facade.registerCommand(CLZNoticeName.OK_GIVE_BUY_PROP_GIFT, ShopCommand);
            AddBtn.initBtn(this.mcShop, CLZNoticeName.HIDE_SHOPING, AddBtn.CLOSE_TWO, "", 4, 1);
            this.mcShop.title_txt.text = GameData.tip["SHOP"];
            if (this._global.seatId == 0)
            {
                this.mcShop.giftBtn.visible = false;
            }
            if (this._global.userInfo.userVo.gp != GameData.QZONE_SID)
            {
            }
            if (this._global.userInfo.userVo.gp == GameData.FRIEND_SID)
            {
                this.mcShop.hotPropBtn.visible = false;
                this.mcShop.interactivePropBtn.visible = false;
            }
            var _loc_1:Array = [[this.mcShop.hotPropBtn, GameData.tip["HOT_PROP"]], [this.mcShop.giftBtn, GameData.tip["GIFT"]], [this.mcShop.vipBtn, "VIP"], [this.mcShop.interactivePropBtn, GameData.tip["INTERACTIVE_PROP"]]];
            this._tabBar = new CLZTabBar(_loc_1);
            var _loc_2:int = 0;
            while (_loc_2 < _loc_1.length)
            {
                
                _loc_1[_loc_2][0].addEventListener(Event.CHANGE, this.changeTabBarHandler);
                _loc_2 = _loc_2 + 1;
            }
            switch(this._nType)
            {
                case GameData.SHOP_HOTPROP_TYPE:
                {
                    this._tabBar.setClickIndex(this.mcShop.hotPropBtn);
                    break;
                }
                case GameData.SHOP_GIFT_TYPE:
                {
                    this._tabBar.setClickIndex(this.mcShop.giftBtn);
                    break;
                }
                case GameData.SHOP_VIP_TYPE:
                {
                    this._tabBar.setClickIndex(this.mcShop.vipBtn);
                    break;
                }
                case GameData.SHOP_INTERACTIVEPROP_TYPE:
                {
                    this._tabBar.setClickIndex(this.mcShop.interactivePropBtn);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }

        private function changeTabBarHandler(event:Event) : void
        {
            var _loc_2:MovieClip = null;
            this.removeAll();
            switch(event.target.name)
            {
                case "hotPropBtn":
                {
                    _loc_2 = GameData.getMovieClip("ShopPropMc");
                    facade.registerMediator(new ShopPropMediator(_loc_2, this._onPlayerVo, GameData.SHOP_HOTPROP_TYPE));
                    break;
                }
                case "giftBtn":
                {
                    _loc_2 = GameData.getMovieClip("ShopGiftMc");
                    facade.registerMediator(new ShopGiftMediator(_loc_2, this._onPlayerVo));
                    break;
                }
                case "vipBtn":
                {
                    _loc_2 = GameData.getMovieClip("ShopVipMc");
                    facade.registerMediator(new ShopVipMediator(_loc_2, this._onPlayerVo));
                    break;
                }
                case "interactivePropBtn":
                {
                    _loc_2 = GameData.getMovieClip("ShopPropMc");
                    facade.registerMediator(new ShopPropMediator(_loc_2, this._onPlayerVo, GameData.SHOP_INTERACTIVEPROP_TYPE));
                    break;
                }
                default:
                {
                    break;
                }
            }
            this.mcShop.conten_mc.addChild(_loc_2);
            _loc_2.x = 0;
            _loc_2.y = 0;
            return;
        }

        private function removeAll() : void
        {
            var _loc_1:* = undefined;
            facade.removeMediator(ShopPropMediator.NAME);
            facade.removeMediator(ShopGiftMediator.NAME);
            facade.removeMediator(ShopVipMediator.NAME);
            while (this.mcShop.conten_mc.numChildren)
            {
                
                _loc_1 = this.mcShop.conten_mc.removeChildAt(0);
                _loc_1 = null;
            }
            return;
        }

        override public function listNotificationInterests() : Array
        {
            return [CLZNoticeName.HIDE_SHOPING, CLZNoticeName.OK_GIVE_BUY_PROP_GIFT];
        }

        override public function handleNotification(param1:INotification) : void
        {
            switch(param1.getName())
            {
                case CLZNoticeName.HIDE_SHOPING:
                {
                    if (Texas.I._mcWindosView.contains(this.mcShop))
                    {
                        Texas.I._mcWindosView.removeChildTo(this.mcShop);
                        viewComponent = null;
                    }
                    facade.removeCommand(CLZNoticeName.SHOP_HOT_PROP_LIST_REQ);
                    facade.removeCommand(CLZNoticeName.SHOP_INTERACTIVE_PROP_LIST_REQ);
                    facade.removeCommand(CLZNoticeName.SHOP_GIFT_LIST_REQ);
                    facade.removeCommand(CLZNoticeName.SHOP_VIP_LIST_REQ);
                    facade.removeCommand(CLZNoticeName.OK_GIVE_BUY_PROP_GIFT);
                    facade.removeMediator(ShopMediator.NAME);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }

        private function get mcShop() : MovieClip
        {
            return viewComponent as MovieClip;
        }

    }
}
